<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>拓深科技</title>
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="assets/ionicons-2.0.1/css/ionicons.min.css" rel="stylesheet"/>
    <link href="assets/plugins/daterangepicker/daterangepicker-bs3.css" rel="stylesheet" />
    <link href="assets/plugins/select2/select2.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/AdminLTE.min.css" rel="stylesheet"/>
    <link href="assets/AdminLTE/dist/css/skins/_all-skins.min.css" rel="stylesheet"/>
    <link href="assets/images/log.ico" rel="shortcut icon">
    <!--&lt;!&ndash;图片热点标记插件&ndash;&gt;-->
    <link href="assets/ipicture/css/iPicture_location.css" rel="stylesheet" media="screen"/>
    <style>
        .table>tbody>tr>td{
            text-align:center;
        }
        .table>thead:first-child>tr:first-child>th{
            text-align:center;
        }
        .changeColor a:hover{
            color: black;
            cursor:pointer;
        }
    </style>

</head>
<body class="hold-transition skin-red sidebar-mini">
<div class="wrapper">
    <!--顶部导航栏开始-->
    <header id="top_header" class="main-header">
        <!-- Logo -->
        <a href="main_page.html" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>T</b>pson</span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>T</b>PSON</span>
        </a>
        <!-- Header Navbar: style can be found in header.less -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- Sidebar toggle button-->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">

                    <!-- User Account: style can be found in dropdown.less -->
                    <li class="dropdown user user-menu">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!--<img src="assets/dist/img/user2-160x160.jpg" class="user-image" alt="User Image">-->
                            <span class="hidden-xs">Administrator</span>
                        </a>
                    </li>
                    <!-- Control Sidebar Toggle Button -->
                </ul>
            </div>
        </nav>
    </header>
    <!--顶部导航栏结束-->
    <!--右侧导航栏开始-->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- Sidebar user panel -->
            <!-- sidebar menu: : style can be found in sidebar.less -->
            <ul id="side_bar" class="sidebar-menu">
                <li class="header">导航栏</li>
                <li class="treeview active">
                    <a href="main_page.html">
                        <i class="fa fa-dashboard text-red"></i>
                        <span>主页</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="alert_log.html">
                        <i class="fa fa-warning text-red"></i>
                        <span>报警记录</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="map_show.html">
                        <i class="fa fa-map-marker text-red"></i>
                        <span>地图展示</span>
                    </a>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-cog text-red"></i>
                        <span>设备管理</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <!--<li><a href="router_status.html"><i class="fa fa-circle-o text-yellow"></i>设备状态 </a> </li>-->
                        <li><a href="router_config.html"><i class="fa fa-circle-o text-yellow"></i>设备配置 </a> </li>
                    </ul>
                </li>
                <li class="treeview">
                    <a href="#">
                        <i class="fa fa-chain-broken text-red"></i>
                        <span>监测点配置</span>
                        <i class="fa fa-angle-left pull-right"></i>
                    </a>
                    <ul class="treeview-menu">
                        <li><a href="monitor_config_map_config.html"><i class="fa fa-circle-o text-yellow"></i>地图配置 </a> </li>
                        <li><a href="monitor_config_sensor_type_input.html"><i class="fa fa-circle-o text-yellow"></i>传感器类别设置 </a> </li>
                        <li><a href="monitor_config_monitor_input.html"><i class="fa fa-circle-o text-yellow"></i>监测点配置 </a> </li>
                        <li><a href="monitor_config_export.html"><i class="fa fa-circle-o text-yellow"></i>数据导入导出 </a> </li>
                    </ul>
                </li>

                <li id="sys_log" class="treeview">
                    <a href="show_log.html">
                        <i class="fa fa-files-o text-red"></i>
                        <span>系统日志</span>
                    </a>
                </li>
            </ul>
        </section>
        <!-- /.sidebar -->
    </aside>
    <!--右侧导航栏结束-->
    <!--内容区开始-->
    <div class="content-wrapper" >
        <section class="content-header">
            <h1>
                <b style="margin-left: 10px">主页</b>
            </h1>
            <ol class="breadcrumb">
                <li><a href="main_page.html"><i class="fa fa-dashboard"></i> 主页</a></li>
            </ol>
        </section>
        <section class="invoice">
            <div class="row">
                <div class="col-lg-2 col-xs-12">
                    <div class="row">
                        <div class="small-box bg-blue changeColor">
                            <div class="inner">
                                <h3 id="monthAlarm">0</h3>

                                <small>最近1月报警次数</small>
                            </div>
                            <div class="icon">
                                <i class="ion ion-nuclear"></i>
                            </div>
                            <a class="small-box-footer" onclick="location.href=encodeURI('alert_log.html?alertType=1')">详情 <i class="fa fa-arrow-circle-right"></i></a>
                        </div>
                    </div>
                    <div class="row">
                        <div class="small-box bg-red changeColor">
                            <div class="inner ">
                                <h3 id="monthIgnoreAlarm">0</h3>
                                <small>最近1月未处理报警事件数</small>
                            </div>
                            <div class="icon">
                                <i class="ion ion-ios-bell"></i>
                            </div>
                            <a class="small-box-footer" onclick="location.href=encodeURI('alert_log.html?alertType=2')">详情<i class="fa fa-arrow-circle-right"></i></a>
                        </div>
                    </div>
                    <div class="row">
                        <div class="box box-warning box-solid">
                            <div class="box-header">
                                <h4 class="box-title"><b>当前设备</b></h4>
                            </div>
                            <div class="box-body">
                                <table id="eq_table" class="table table-bordered table-striped" >
                                    <tbody id="eq_table_tbody">

                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div  class="col-lg-10 col-xs-12">
                    <div  style="border: none;height: 700px;">
                        <div id="carousel-example-generic" class="carousel slide" data-interval="false" align="center" style="width: 100%;height: 100%">
                            <ol id="carouselIndicators" class="carousel-indicators" >

                            </ol>
                            <div id="iPicture" class="carousel-inner"style="width: 100%;height: 100%">

                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </section>

        <div class="clearfix"></div>
    </div><!-- /.content-wrapper -->
    <!--内容区结束-->
    <!--页脚开始-->
    <footer class="main-footer no-print">
        <div class="pull-right hidden-xs">
            <b>Version</b>  3.1.4
        </div>
        <strong>Copyright &copy; 2015-2016 <a href="http://www.tpson.cn/" target="_blank">拓深科技</a>.</strong> All rights reserved.
    </footer>
    <!--页脚结束-->
</div>

<script src="assets/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<!--<script src="assets/plugins/select2/select2.full.min.js"></script>-->
<script src="assets/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!--<script src="assets/plugins/fastclick/fastclick.min.js"></script>-->
<script src="assets/layer-v2.2/layer/layer.js"></script>
<script src="assets/AdminLTE/dist/js/app.min.js"></script>
<script src="assets/AdminLTE/dist/js/demo.js"></script>
<!--图片热点标记插件-->
<script src="assets/ipicture/js/jquery.ipicture_location.js"></script>

<script src="js/alert_check.js"></script>
<script>
    var server;
    var imgs = new Array();
    var locationData = new Array();
    var ignoreAlarmLocalId = new Array();
    $(function () {
        var path = document.location.pathname;
        var href = document.location.href;
        if(path =='/'){
            var index = href.indexOf(path,href.indexOf(path)+2);
        }else {
            var index = href.indexOf(path);
        }
        var localPath = href.substring(0,index);
        var localName = path.substring(0,path.substr(1).indexOf('/')+1);
        server = localPath + localName;
        socketInit(server.substring(5));
        getIgnoreAlarm();
        getMainMap();
        ReadRouterTable();
        gitAlarmNum();
        window.onload = checkAlert(server);
    });
    function getMainMap() {
        $.ajax({
            url: server + "/xk/xkGeoLocation/getTree",
            success:function (data) {
                var jsonObj = JSON.parse(data);
                for(var i in jsonObj.data){
                    var level1 = jsonObj.data;
                    var obj = {
                        Map_id : level1[i].id,
                        Map_name : level1[i].name,
                    };
                    var ii = 0;
                    var level1Obj = {
                        text:level1[i].name,
                        id:level1[i].id,
                        value:ii++,
                        level:1,
                        parentId:0,
                    };
                    if(level1[i].children != null)
                    {
                        var level2 = level1[i].children;
                        var level2Arr = [];
                        var jj = 0;
                        for(var j in level2){
                            var level2Obj = {
                                text: level2[j].name,
                                id: level2[j].id,
                                value:jj++,
                                parentId:level1[i].id,
                                posX:level2[j].posX,
                                posY:level2[j].posY,
                                level:2,
                            };
                            if(level2[j].children != null)
                            {
                                var level3 = level2[j].children;
                                var level3Arr = [];
                                for(var k in level3){
                                    var level3Obj = {
                                        text: level3[k].name,
                                        id: level3[k].id,
                                        level:3,
                                        parentId:level2[j].id,
                                    };
                                    level3Arr.push(level3Obj);
                                }
                                level2Obj .children = level3Arr;
                            }
                            level2Arr.push(level2Obj);
                        }
                        level1Obj.children = level2Arr;
                    }
                    locationData.push(level1Obj);

                    if(i == 0){
                        $('#carouselIndicators').append(
                                '<li data-target="#carousel-example-generic" data-slide-to='+i+' class="active"></li>'
                        );
                    }else{
                        $('#carouselIndicators').append(
                                '<li data-target="#carousel-example-generic" data-slide-to='+i+' class=""></li>'
                        );
                    }
                    imgs.push(obj);
                }
                eachImg(imgs.length-1);
                $('#carousel-example-generic').append(
                        '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">'+
                        '<span class="fa fa-angle-left"></span>'+
                        '</a>'+
                        '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">'+
                        '<span class="fa fa-angle-right"></span>'+
                        '</a>'
                );
            }
        });
    }
    //按顺序加载图片
    function eachImg(i){
        var j = i-1;
        if(i == 0){
            $('#iPicture').append(
                    '<div class="item  active" align="center" style="width: 100%;height: 100%"><div id='+"iPicture"+imgs[i].Map_id+' style="width: 100%;height: 100%"><div class="ip_slide" id='+"map_div"+imgs[i].Map_id+' style="width: 100%;height: 100%">'+
                    '<img src='+server+"/xk/xkGeoLocation/mapDownload?id="+imgs[i].Map_id+' id='+"Img"+imgs[i].Map_id+' alt='+imgs[i].Map_name+' style="width: 100%;height: 100%" onload="eachImg('+j+')" onerror="errorImg('+i+')">'+
                    '</div></div>'+
                    '<div class="carousel-caption">'+imgs[i].Map_name+'</div>'+
                    '</div>'
            );
            Readlocation(i);
        }else if(i<imgs.length && i>0){
            $('#iPicture').append(
                    '<div class="item " align="center" style="width: 100%;height: 100%"><div id='+"iPicture"+imgs[i].Map_id+' style="width: 100%;height: 100%"><div class="ip_slide" id='+"map_div"+imgs[i].Map_id+' style="width: 100%;height: 100%">'+
                    '<img src='+server+"/xk/xkGeoLocation/mapDownload?id="+imgs[i].Map_id+' id='+"Img"+imgs[i].Map_id+' alt='+imgs[i].Map_name+ ' style="width: 100%;height: 100%" onload="eachImg('+j+')" onerror="errorImg('+i+')">'+
                    '</div></div>'+
                    '<div class="carousel-caption">'+imgs[i].Map_name+'</div>'+
                    '</div>'
            );
            Readlocation(i);
        }else {
            $( "#iPicture" ).iPicture({});
            return 1;
        }
    }
    //图片加载失败时用自定义图片
    function errorImg(i){
        var j = i+1;
        id = "#Img"+imgs[i].Map_id;
        $(id).attr("src","assets/地图加载失败页2.jpg");
    }
    function ReadRouterTable() {
        $.ajax({
            url:server+"/xk/xkDevice/getAll" ,
            success:function (data_in) {
                var json = JSON.parse(data_in);
                if(json.length == 0){
                    layer.alert('没有数据！',{
                        closeBtn: 0
                    });
                }else{
                    for(var i in json.data){
                        var datas = json.data;
                        var tr = "";
                        if(datas[i].status==1){
                            tr = "<tr>" +"<td><span style='color: limegreen'>" + datas[i].name + "</span></td>"+ "</tr>";
                        }else {
                            tr = "<tr>" +"<td><span style='color: red'>" + datas[i].name + "</span></td>"+ "</tr>";
                        }
                        $('#eq_table').append(tr);
                    }
                }
            }
        });
    }
    function Readlocation(i){
        var showType = "ltr-slide";
        var showColor = "roundBgG";
        var areaFlag=0;
        var buildFlag;
        var floorFlag;
//        for(var alarm_i in ignoreAlarmLocalId){
//            if(locationData[i].id == ignoreAlarmLocalId[alarm_i]){
//                areaFlag = 1;
//                break;
//            }
//        }
        for(var j in locationData[i].children){
            buildFlag = 0;
            for(var build_j in ignoreAlarmLocalId){
                if(locationData[i].children[j].id == ignoreAlarmLocalId[build_j].build){
                    buildFlag = 1;
                    break;
                }
            }
            if(buildFlag){
                var x = (parseFloat(locationData[i].children[j].posX) * 100-0.7);
                var y = (parseFloat(locationData[i].children[j].posY) * 100-0.9);
                if(x>50&&y<50){
                    showType = "rtl-slide";
                }else if(x<50&&y>50){
                    showType = "btt-slide";
                }else if(x>50&&y>50){
                    showType = "ttb-slide";
                }
                x = x>0?x+'%':0;
                y = y>0?y+'%':0;
                var divs =  "";
                divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';z-index: 100;" data-tooltipbg="bgwhite" data-round="roundBgR"  data-animationtype="'+showType+'" >' +
                        '<div class="row" style="height: auto;width: 100px;margin: auto">' +
                        '   <div class="box box-primary box-solid">' +
                        '       <div class="box-header"><h4>'+locationData[i].children[j].text+'</h4></div>' +
                        '       <div class="box-body">' +
                        '           <table class="table table-bordered table-striped">' +
                        '               <tbody id="'+locationData[i].children[j].text+'">' +
                        '               </tbody>' +
                        '           </table>' +
                        '       </div>' +
                        '       </div>' +
                        '   </div>' +
                        '</div>';
                $("#map_div"+imgs[i].Map_id).append(divs);

                var tr ="";
                for(var k in locationData[i].children[j].children){
                    floorFlag = 0;
                    for(var floor_id in ignoreAlarmLocalId){
                        if(locationData[i].children[j].children[k].id == ignoreAlarmLocalId[floor_id].floor){
                            floorFlag = 1;
                            break;
                        }
                    }
                    if(floorFlag){
                        tr += "<tr><td class='changeColor' style='border: solid;'><a  onclick=changePage('"+locationData[i].children[j].children[k].id+"','"+locationData[i].children[j].children[k].text+"') ><span style='color: red'>" + locationData[i].children[j].children[k].text +"</span></a></td><tr>"
                    }else{
                        tr += "<tr><td class='changeColor'><a  onclick=changePage('"+locationData[i].children[j].children[k].id+"','"+locationData[i].children[j].children[k].text+"')>" + locationData[i].children[j].children[k].text +"</a></td><tr>"
                    }

                }
                $("#"+locationData[i].children[j].text).append(tr);
            }else {
                var x = (parseFloat(locationData[i].children[j].posX) * 100-0.7);
                var y = (parseFloat(locationData[i].children[j].posY) * 100-0.9);
                if(x>50&&y<50){
                    showType = "rtl-slide";
                }else if(x<50&&y>50){
                    showType = "btt-slide";
                }else if(x>50&&y>50){
                    showType = "ttb-slide";
                }
                x = x>0?x+'%':0;
                y = y>0?y+'%':0;
                var divs =  "";
                divs ='<div class="ip_tooltip ip_img32" style="top: '+y+'; left: '+x+';z-index: 100;" data-tooltipbg="bgwhite" data-round="'+showColor+'"  data-animationtype="'+showType+'" >' +
                        '<div class="row" style="height: auto;width: 100px;margin: auto">' +
                        '   <div class="box box-primary box-solid">' +
                        '       <div class="box-header"><h4>'+locationData[i].children[j].text+'</h4></div>' +
                        '       <div class="box-body">' +
                        '           <table class="table table-bordered table-striped">' +
                        '               <tbody id="'+locationData[i].children[j].text+'">' +
                        '               </tbody>' +
                        '           </table>' +
                        '       </div>' +
                        '       </div>' +
                        '   </div>' +
                        '</div>';
                $("#map_div"+imgs[i].Map_id).append(divs);

                var tr ="";
                for(var k in locationData[i].children[j].children){
                    tr += "<tr><td class='changeColor'><a onclick=changePage('"+locationData[i].children[j].children[k].id+"','"+locationData[i].children[j].children[k].text+"')>" + locationData[i].children[j].children[k].text +"</a></td><tr>"
                }
                $("#"+locationData[i].children[j].text).append(tr);
            }
        }
    }
    function changePage(id,name){
        var contant = "map_show.html?mapId=" + id + "&name=" + name
        location.href=encodeURI(contant);
    }
    function getIgnoreAlarm(){
        $.ajax({
            url:server+"/xk/alarm/getAllIgnore" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in).data;
                for(var i in json){
                    var LocationId = {
                        area:json[i].geo_1_id,
                        build: json[i].geo_2_id,
                        floor:json[i].geo_3_id,
                    }
                    ignoreAlarmLocalId.push(LocationId);
                }
            }
        });
    }
    function gitAlarmNum(){
        $.ajax({
            url:server+"/xk/alarm/getOneMonthAll" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in).number;
                $("#monthAlarm").html(json);
            }
        });
        $.ajax({
            url:server+"/xk/alarm/getOneMonthIgnore" ,
            async:false,
            success:function (data_in) {
                var json = JSON.parse(data_in).number;
                $("#monthIgnoreAlarm").html(json);
            }
        });
    }
</script>
</body>
</html>